/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK1.6+
 * <p>
 * 鐗堟潈鎵?鏈?(C)锛氭睙鑻忔绱㈣蒋浠舵湁闄愬叕鍙?
 * <p>
 * 鍏徃鍚嶇О锛氭睙鑻忔绱㈣蒋浠舵湁闄愬叕鍙?
 * <p>
 * 鍏徃鍦板潃锛氳嫃宸炴柊鍖洪潚灞辫矾1鍙风储杩疄璁熀鍦?
 * <p>
 * 缃戝潃: http://www.oceansoft.com.cn
 * <p>
 * 鐗堟湰: 娓ｅ湡杞︾洃绠″钩鍙癬1.0
 * <p>
 * 浣滆??: 090922(闄堜紵)
 * <p>
 * <p>
 * 鏂囦欢鍚?: DataChangeNotificationListener.java
 * <p>
 * 绫讳骇鐢熸椂闂?:2011-12-20 涓嬪崍1:56:13
 * <p>
 * 璐熻矗浜?: 090922(闄堜紵)
 * <p>
 * 鎵?鍦ㄧ粍: 娓ｅ湡杞︾洃绠″钩鍙?
 * <p>
 * 鎵?鍦ㄩ儴闂?: 寮?鍙戜竴閮?-鎶?鏈簩閮?
 * <p>
 * email锛歫avacspring@gmail.com
 * <p>
 * <p>
 */
package com.oceansoft.mobile.econsole.modules.dcn;

import com.oceansoft.mobile.econsole.modules.dcn.dispatcher.IDispatchable;
import com.oceansoft.mobile.econsole.modules.dcn.processor.OuterCoreProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ClassName: DataChangeNotificationListener
 * Desc: Oracle DCN处理器
 * Date： 2016/11/16
 * Created：shaom
 */
public class DataChangeNotificationListener {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    private static final String SQL_BIND_OUTER_TABLE_QUERY = "SELECT * FROM DDX_OU_QUERY_SERVICE WHERE 1 = 2";

    private final DbChangeRegistration dbr;

    public DataChangeNotificationListener(DbChangeRegistration dbr) {
        this.dbr = dbr;
    }

    public void listening(IDispatchable dispatcher) {
        //1.开始判断传入接口实现是哪个分发器,从而构建监听表
        String listenSQL;
        if (dispatcher instanceof OuterCoreProcessor) {
            listenSQL = SQL_BIND_OUTER_TABLE_QUERY;
        } else {
            throw new RuntimeException("初始化DCN监听器失败 错误:指定任务调度器错误!");
        }

        dbr.addListener(dispatcher, listenSQL);
    }

    /**
     * 注销DCN监听
     */
    public void stopListening() {
        dbr.stopListening();
    }
}
